<div class="fly-header layui-bg-black">
    <div class="layui-container">
        <a class="fly-logo" href="{{ path('fortend_homepage') }}">
            <img src="../res/images/logo.png" alt="layui">
        </a>
        <ul class="layui-nav fly-nav layui-hide-xs">
            <li class="layui-nav-item layui-this">
                <a href="/"><i class="iconfont icon-jiaoliu"></i>交流</a>
            </li>
            <li class="layui-nav-item">
                <a href="case/case.html"><i class="iconfont icon-iconmingxinganli"></i>案例</a>
            </li>
            <li class="layui-nav-item">
                <a href="http://www.layui.com/" target="_blank"><i class="iconfont icon-ui"></i>框架</a>
            </li>
        </ul>
        <ul class="layui-nav fly-nav-user">

            {% if data.user_info | length == 0 %}
            <!-- 未登入的状态 -->
            <li class="layui-nav-item">
                <a class="iconfont icon-touxiang layui-hide-xs" href="user/login.html"></a>
            </li>
            <li class="layui-nav-item">
                <a href="{{ path('fortend_login') }}">登入</a>
            </li>
            <li class="layui-nav-item">
                <a href="{{ path('fortend_register') }}">注册</a>
            </li>
            {% else %}
            <!-- 登入后的状态 -->
            <li class="layui-nav-item">
              <a class="fly-nav-avatar" href="javascript:;">
                <cite class="layui-hide-xs"></cite>
                <i class="iconfont icon-renzheng layui-hide-xs">{{ data.user_info.nickname }}</i>
                <img class="self-avatar" src="{{ data.user_info.avatar | default('https://tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg') }}">
              </a>
              <dl class="layui-nav-child">
                <dd><a href="{{ path('fortend_user_index') }}"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a></dd>
                <dd><a href="{{ path('fortend_user_set') }}"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
                <hr style="margin: 5px 0;">
                <dd class="exit-login" style="cursor: pointer;"><a style="text-align: center;">退出登录</a></dd>
              </dl>
            </li>
            {% endif %}
        </ul>
    </div>
</div>

<script>
    layui.cache.page = location.href;
    layui.cache.user = {
        username: '游客'
        ,uid: -1
        ,avatar: '{{ asset('resource/images/avatar/00.jpg') }}'
        ,experience: 83
        ,sex: '男'
    };
    layui.config({
        version: "3.0.0"
        ,base: '{{ asset('resource/mods/') }}'
    }).extend({
        fly: 'index'
    }).use('fly');

    $(function () {
        $('.exit-login').on('click', function() {
            $.post('{{ path('api_exitLogin') }}', function (res) {
                if (res.errorCode === 0) {
                    layer.msg(res.message);
                    setTimeout(function () {
                        location.href = '{{ path('fortend_homepage') }}';
                    }, 1000);
                } else {
                    layer.alert(res.message);
                }
            })
        });

        $('.self-avatar').on('click', function() {
            $('.layui-nav-child').toggle();
        })
    })
</script>